/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ConnectData;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author
 */
public class AppSetting {

    private static final Hashtable<String, String> setting = new Hashtable<String, String>();

    static {
        BufferedReader BR =null;
        try {
            BR = new BufferedReader(new InputStreamReader(new FileInputStream("Config.cfg")));
            String line = null;
            while ((line=BR.readLine())!= null){
                String[] temp = line.split("=");
                if(!setting.contains(temp[0].trim()) && temp.length > 1){
                    setting.put(temp[0].trim(), temp[1].trim());
                }
            }
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(null, "File Config.cfg not found! Please use Config Tool to remake this file!", "Error", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "I/O error!", "Error", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        } finally {
            try {
                BR.close();
            } catch (IOException ex) {
                Logger.getLogger(AppSetting.class.getName()).log(Level.SEVERE, null, ex);
            } catch (NullPointerException ex){
                
            }
        }
    }
    
    public static String getSetting(String key) {
        if(setting.containsKey(key)){
            return setting.get(key);
        }
        return "";
    }

}
